import {Page} from '@/base/Page';
import {Health} from '@/base/model/Health';
import {getHealthList} from '@/base/api/FamilyApi';
import {isEmpty} from '@/base/util/Strings';

class Form {
  createBegin = '';
  createEnd = '';
  date = [];
}

export class MassageBloc {
  form = new Form();
  paged: Page<Health> = new Page<Health>([], 0, 1, 15, 0, []);
  loading = false;

  load(pageIndex: number, pageSize: number, memberId: number) {
    if (!isEmpty(this.form.date) && !isEmpty(String(this.form.date[0]))) {
      // @ts-ignore
      this.form.createBegin = this.form.date[0].getTime() || '';
      // @ts-ignore
      this.form.createEnd = this.form.date[1].getTime() + 24 * 60 * 60 * 1000 || '';
    } else {
      this.form.createBegin = '';
      this.form.createEnd = '';
    }
    this.loading = true;
    return getHealthList({
      pageIndex,
      pageSize,
      memberId,
      sortDirection: 'DESC',
      createBegin: this.form.createBegin,
      createEnd: this.form.createEnd
    }).then((res) => {
      this.paged = res.data;
    }).finally(() => {
      this.loading = false;
    });
  }

  // removeItem(dateItem: Health) {
  //   this.loading = true;
  //   return deleteHealth(dateItem.id)
  //     .finally(() => {
  //       this.loading = false;
  //     });
  // }
}
